package src.dp.sequence;

import java.util.Arrays;

public class no674 {//最长连续递增序列

    //法1：双指针
    public int findLengthOfLCIS(int[] nums) {
        //int len = 1;  //要么用len记录长度，要么计算right-left+1即为子数组长
        int res = 1;
        int left = 0;
        for (int right = 1; right < nums.length; right++) {
            if (nums[right] > nums[right - 1]) {
                //len++;
                res = Math.max(res, right - left + 1);
            } else {
                left = right;
                //len=1;
            }
        }
        return res;
    }

    //法2：动规
    public int findLengthOfLCIS2(int[] nums) {
        int res = 1;
        int[] dp = new int[nums.length];
        //dp[0] = 1;
        Arrays.fill(dp, 1);
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i - 1]) {
                dp[i] = dp[i - 1] + 1;
            }
            if (dp[i] > res) {
                res = dp[i];
            }
            //res = Math.max(res, i);
        }
        return res;
    }

    //法3：贪心
    public int findLengthOfLCIS3(int[] nums) {
        int res = 1;
        int count = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i - 1]) {
                count++;
            } else count = 1;

            if (count > res) res = count;
        }
        return res;
    }

}
